package com.bins.dentist.clinic.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bins.dentist.clinic.model.dto.PermissionDto;
import com.bins.dentist.clinic.model.dto.PermissionPageDto;
import com.bins.dentist.clinic.model.dto.RolePermDto;
import com.bins.dentist.clinic.model.vo.PermissionTreeVo;
import com.bins.dentist.clinic.model.vo.PermissionVo;
import com.bins.dentist.clinic.model.vo.ResultVo;
import com.bins.dentist.clinic.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bins
 * @since 2023-02-20 20:53:31
 */
@RestController
@RequestMapping("/system/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @GetMapping("/page")
    public ResultVo<IPage<PermissionVo>> pageList(PermissionPageDto pageDto) {
        return ResultVo.ok().data(permissionService.getPage(pageDto));
    }

    @GetMapping("/detail")
    public ResultVo<PermissionVo> detail(PermissionDto dto) {
        return ResultVo.ok().data(permissionService.getDetailById(dto));
    }

    @PostMapping("/save")
    public ResultVo<PermissionVo> savePermission(@RequestBody PermissionDto dto) {
        return ResultVo.ok().data(permissionService.savePermission(dto));
    }

    @PostMapping("/delete")
    public ResultVo<Integer> deletePermission(@RequestBody PermissionDto dto){
        return ResultVo.ok().data(permissionService.deletePermission(dto)) ;
    }

    @GetMapping("/permTreeList")
    public ResultVo<List<PermissionTreeVo>> permTreeList() {
        return ResultVo.ok().data(permissionService.permTreeList());
    }

    @PostMapping("/bindRole")
    public ResultVo<Integer> bindRole(@RequestBody RolePermDto dto) {
        return ResultVo.ok().data(permissionService.bindRole(dto));
    }

}

